﻿app.controller('GHProvideOrderController',
[
    '$rootScope',
    '$scope',
    '$localStorage',
    '$state',
    '$stateParams',
    '$modal',
    '$confirm',
    'ManagerPackFactory', 'BitcoinFactory', '$filter', 'CN_TructiepFactory', 'commonFactory',
    function ($rootScope, $scope, $localStorage, $state, $stateParams, $modal,$confirm, ManagerPackFactory, BitcoinFactory, $filter, CN_TructiepFactory) 
    {
        $scope.title = "GH Detail",
        $scope.messeger = "",
        $scope.orderId = $stateParams.orderId,
        $scope.RoomCode = $stateParams.roomCode,
        $scope.popup = function (windowClass, StyleModal, Controller, size) {
            $modal.open({
                windowClass: windowClass,
                templateUrl: StyleModal,
                controller: Controller,
                size: size,
                resolve: {
                    messeger: function () {
                        return $scope.messeger;
                    },
                    title: function () {
                        return $scope.title;
                    }
                }
            })
        },
        $scope.ProvideOrderList = [],
        ShowProvideOrderRecieve($scope.RoomCode ,$localStorage.user.UserId);
        function ShowProvideOrderRecieve(RoomCode,UserId) {
            commonFactory.showProvideOrderRecieve(RoomCode, UserId).then(function (rsp) {
                if (rsp.data.Status) {
                    $scope.ProvideOrderList = rsp.data.Result;
                } else {
                    $scope.messeger = rsp.data.Msg;
                }
            }, function (error) {
                $scope.status = 'Unable to load profile data: ' + error.message;
            });
        };
        $scope.doApprove = function (item) {
                DoApprove(item); 
        };

        function DoApprove(item) {
            commonFactory.approveProvideOrder(item.Id, item.RoomCode).then(function (rsp) {
                if (rsp.data.Status) {
                    //console.log(item.Id);
                    $state.go('app.ghprovideorder', { orderId: item.Id, RoomCode: item.roomCode })
                } else {
                    $scope.messeger = rsp.data.Msg,
                    $scope.title = 'Warning',
                    $scope.popup('modal-message modal-warning', "WarningModal");
                }
            }, function (error) {
                $scope.status = 'Unable to load profile data: ' + error.message;
            });
        }
    }
]);
